package com.cscp.javastudy.juc.streamcalculate;

import java.util.Arrays;
import java.util.List;

/**
 *
 */
public class StreamCalDemo1 {

    public static void main(String[] args) {
        User user1 = new User(1,"a",21);
        User user2 = new User(2,"b",22);
        User user3 = new User(3,"c",23);
        User user4 = new User(4,"d",24);
        User user5 = new User(6,"e",25);

        List<User> userList = Arrays.asList(user1, user2, user3, user4, user5);

        /*
         *  1 - ID必须是偶数
         *  2 - 年龄大于23
         *  3 - 转换用户名为大写
         *  4 - 用户名字母倒着排序
         *  5 - 只输出一个用户
         */
        userList.stream()
                .filter(u->{return u.getId()%2 == 0;})
                .filter(u->{return u.getAge()>23;})
                .map(u->{return u.getName().toUpperCase();})
                .sorted((name1, name2)->{return name2.compareTo(name1);})
                .limit(1)
                .forEach(System.out::println);

    }
}
